package com.company.lagou.homework.homework2;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class StudentTest {

    static Scanner sc = new Scanner(System.in);
    static List<Student> l = new ArrayList<Student>();
    static Student s = new Student();
    static boolean a = true;

    /*
    实现操作界面
     */
    public static void main(String[] args) {

        System.out.println("欢迎来到学生管理系统");
        System.out.println("【1】添加");
        System.out.println("【2】查找");
        System.out.println("【3】修改");
        System.out.println("【4】删除");
        System.out.println("【5】遍历");
        System.out.print("请选择您的操作:");

        while(a) {
            String stus = sc.nextLine();
            switch(stus) {
                case "1":
                    add();
                    break;
                case "2":
                    sel();
                    break;
                case "3":
                    set();
                    break;
                case "4":
                    del();
                    break;
                case "5":
                    show();
                    break;
            }
        }

    }

    /*
    增加功能
     */
    static void add() {
        while(a = true) {
            System.out.println("请输入学生学号");
            s.setID(sc.next());
            System.out.println("请输入学生姓名");
            s.setName(sc.next());
            System.out.println("请输入学生年龄");
            s.setAge(sc.nextInt());
            System.out.println("添加成功");
            l.add(s);
            break;
        }
    }

    /**
     * 查询功能
     */
    static void sel() {
        for (Student s : l) {
            System.out.println("姓名:"+s.getName()+" "+"年龄:"+s.getAge());
        }
    }

    /**
     * 删除功能
     */
    static void del() {
        System.out.println("请输入要删除的学号");
        String ID = sc.next();
        for(int i=0;i<l.size();i++) {
            if(ID.equals(l.get(i).getID())) {
                l.remove(i);
                System.out.println("删除成功");
            }else {
                System.out.println("删除失败未找到学生");
            }
        }
    }

    /**
     * 修改功能
     */
    static void set() {
        System.out.println("请输入要修改学生的学号");
        String ID = sc.next();
        for(int i=0;i<l.size();i++) {
            if(ID.equals(l.get(i).getID())) {
                System.out.println("发现学生正在修改");
                System.out.println("请输入修改后的姓名");
                String name = sc.next();
            }else{
                System.out.println("修改失败未找到学生");
            }
        }

    }
    /**
     * 遍历功能
     */
        static void show() {
            System.out.println(l);
        }

}


